package com.qf;

import com.qf.pojo.User;
import org.junit.Test;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * Create by 周志豪 on 2022/8/26  16:42
 *
 * @authoe 周志豪
 * @veision 1.0
 * //TODO  想好了再去做
 * @since 1.0
 */
public class test01 {

    @Test
    public void test01(){
        User user =new User();
        System.out.println(user);//com.qf.pojo.User@1b4fb997
    }

    @Test
    public void test02(){
        //配置好bean后，向spring要对象

        //写配置文件的名字
        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");

        //1、写配置中的id名,根据名来获取
        Object bean = context.getBean("user");

        User bean1 = (User) context.getBean("user");

        System.out.println(bean);//com.qf.pojo.User@262b2c86

        System.out.println(bean1);//com.qf.pojo.User@262b2c86

        //2、根据类型获取，但此时不能有两个相同类型的对象
        User bean2 = (User) context.getBean(User.class);
        // No qualifying bean of type 'com.qf.pojo.User' available: expected single matching bean but found 2: user,user2
        System.out.println(bean2);


    }









}
